﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Equin.ApplicationFramework;

namespace TimeReporter
{
    public partial class SingleProjectView : UserControl
    {
        ProjectList theProjects = ProjectList.getInstance();
        BindingSource _masterBS = new BindingSource();
        BindingSource _childBS = new BindingSource();

        public SingleProjectView()
        {
            InitializeComponent();
            dgTaskView.AutoGenerateColumns = false;
            dgTaskView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dgTaskView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgTaskView.AllowUserToResizeColumns = false;
            dgTaskView.AllowUserToResizeRows = false;
            dgTaskView.ScrollBars = ScrollBars.Vertical;

            _masterBS.PositionChanged += new EventHandler(_masterBS_PositionChanged);

            DataGridViewColumn c1 = new DataGridViewTextBoxColumn();
            c1.DataPropertyName = "TimeSpent";
            c1.Name = "Time spent";
            //c1.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
            dgTaskView.Columns.Add(c1);

            DataGridViewColumn c2 = new DataGridViewTextBoxColumn();
            c2.DataPropertyName = "StartDateTime";
            c2.Name = "Start date/time";
            //c2.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
            dgTaskView.Columns.Add(c2);

            DataGridViewColumn c3 = new DataGridViewTextBoxColumn();
            c3.DataPropertyName = "EndDateTime";
            c3.Name = "End date/time";
            //c3.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
            dgTaskView.Columns.Add(c3);

            _masterBS.DataSource = theProjects;
            _childBS.DataSource = _masterBS;
            _childBS.DataMember = "theTasks";

            lstProjects.DataSource = _masterBS;
            lstProjects.DisplayMember = "ProjectName";
            dgTaskView.DataSource = _childBS;

            

        }

        void _masterBS_PositionChanged(object sender, EventArgs e)
        {
            Console.WriteLine("Position changed");
            _childBS.RemoveFilter();
        }

        private void dateTimePicker_ValueChanged(object sender, EventArgs e)
        {            
            _childBS.Filter = String.Format("StartDateTime > {0:yyyy-MM-dd} , EndDateTime < {1:yyyy-MM-dd}", dtStartDate.Value, dtEndDate.Value);     
        }

        private void btnClearDateRange_Click(object sender, EventArgs e)
        {
            _childBS.RemoveFilter();
        }
    }
}
